package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import VO.User;

import DAO.UserDao;

public class register extends HttpServlet {
	public register() {
		super();
	}
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			
		String account = request.getParameter("account");
		System.out.print(account);
		String name = request.getParameter("name");
		String tele = request.getParameter("tele");
		String email = request.getParameter("mail");
		String password = request.getParameter("password");
		
		UserDao udao=new UserDao();
		if(account!=null&&!account.isEmpty()){
			if(udao.userIsExist(account)){
				User user=new User();
				user.setAccount(account);
				user.setPassword(password);
				user.setName(name);
				user.setMail(email);
				user.setTele(tele);
				udao.saveUser(user);
				request.setAttribute("info", "注册成功<br>");
				
			}else{
				request.setAttribute("info", "错误：此用户已存在");	
			}
		}
		response.sendRedirect("/Gym/register_successed.jsp");
	//	request.getRequestDispatcher("../zhucesuccess.jsp").forward(request,response);
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
